package cn.wolfcode.luowowo.article.domain;

import cn.wolfcode.luowowo.common.domain.BaseDomain;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

@Setter
@Getter
@ToString
public class Viewpoint extends BaseDomain {
    public static final Integer STATE_COMMEND = 0; //取消推荐
    public static final Integer STATE_UNCOMMEND = 1; //推荐
    //父景点id
    private Long parentId;
    //关联目的地id
    private Long destId;
    //景点名称
    private String name;
    //标题
    private String title;
    // 景点封面
    private String coverUrl;

    private String[] coverUrls;

    //景点简介
    private String info;
    //景区电话
    private String phone;
    //景区官网
    private String internetSite;
    //用时参考
    private Integer timeCost = 0;
    //交通
    private String transport;
    //门票
    private String ticket;
    //开放时间
    private String openTime;
    //热门景点
    private Integer hot = 0;
    //多少人去过
    private Integer cameNum;
    //评论数量
    private Integer replyNum;
    //收藏数量
    private Integer favorNum;
    //状态
    private Integer status = 0;

    private List<Viewpoint> children = new ArrayList<>();

    public String getStatusName() {
        return status == 1 ? "推荐" : "取消推荐";
    }

    public String getTimeCostName() {
        String msg = "1小时以下";
        if (timeCost == 1) {
            msg = "1-3小时";
        } else if (timeCost == 2) {
            msg = "3小时以上";
        }
        return msg;
    }

    public String getCoverUrl() {
        if (coverUrls == null) {
            return null;
        }

        StringBuilder sb = new StringBuilder();
        for (String cu : coverUrls) {
            sb.append(cu).append(";");
        }
        sb.deleteCharAt(sb.length() - 1);
        coverUrl = sb.toString();
        return coverUrl;
    }

    public String[] getCoverUrls() {
        if (!StringUtils.hasLength(coverUrl)) {
            return null;
        }
        String[] vals = coverUrl.split(";");
        coverUrls = new String[vals.length];
        for (int i = 0; i < vals.length; i++) {
            coverUrls[i] = vals[i];
        }
        return coverUrls;
    }

}
